package com.tianhui.consignortwofei.mvp.ui.activity.display;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonResponse;
import com.fgs.common.CommonView;
import com.fgs.common.progress.ExceptionHandle;
import com.fgs.common.progress.ObserverResponseListener;
import com.fgs.common.utils.DateUtil;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseActivity;
import com.tianhui.consignortwofei.interf.IChartViewInfo;
import com.tianhui.consignortwofei.mvp.model.StatisticsModel;
import com.tianhui.consignortwofei.mvp.model.enty.ChartViewInfo;
import com.tianhui.consignortwofei.mvp.model.enty.statistics.OrderStatisticalInfo;
import com.tianhui.consignortwofei.widget.BarChartView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * @author fgs
 * @date 2021/6/15
 * @description
 **/
public class CumulativeDataActivity extends BaseActivity {

    @BindView(R.id.activity_cumulative_data_driverBarCharView)
    BarChartView driverBarChartView;
    @BindView(R.id.activity_cumulative_data_carBarCharView)
    BarChartView carBarChartView;
    @BindView(R.id.activity_cumulative_data_orderBarCharView)
    BarChartView orderBarChartView;

    private StatisticsModel statisticsModel;

    @Override
    public int getLayoutId() {
        return R.layout.activity_cumulative_data;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public void init() {
        setTitle("累计数据");
        statisticsModel = new StatisticsModel();
        requestDriverCarData();
        requestOrderData();
    }

    private void requestOrderData() {
        String date = DateUtil.getStandardTime(System.currentTimeMillis(), "yyyy-MM-dd");
        Map<String, String> map = new HashMap<>();
        map.put("dates", date);
        statisticsModel.orderStatisticsInfoModel(this, map, false, this.bindLifecycle(), new ObserverResponseListener<CommonResponse<List<OrderStatisticalInfo>>>() {
            @Override
            public void onNext(CommonResponse<List<OrderStatisticalInfo>> commonResponse) {
                if (commonResponse.getCode() == 20000) {
                    List<OrderStatisticalInfo> list = commonResponse.getData();
                    if (list!= null && list.size() > 0){

                        processOrderStatisticsInfo(list);
                    }
                } else {
                    showToast(commonResponse.getMsg());
                }
            }

            @Override
            public void onError(ExceptionHandle.ResponseThrowable e) {
                showToast(e.message);
            }
        });
    }

    private void processOrderStatisticsInfo(List<OrderStatisticalInfo> list) {
        List<IChartViewInfo> orderStatisticsInfoList = new ArrayList<>();
        ChartViewInfo driverResultInfo;
        OrderStatisticalInfo info = null;
        int resultSize = list.size();
        for (int i = 0; i < resultSize; i++) {
            info = list.get(i);
//            if (!TextUtils.isEmpty(info.belongarea) && info.belongarea.equals("2")) {
            driverResultInfo = new ChartViewInfo();
            driverResultInfo.value = info.total;
            driverResultInfo.label = info.createtime;
            orderStatisticsInfoList.add(driverResultInfo);

//            }

        }
        orderBarChartView.setBarChartData(orderStatisticsInfoList);
    }

    private void requestDriverCarData() {

    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

}
